import numpy as np
import pandas as pd
from sklearn.preprocessing import StandardScaler
import tensorflow as tf
import joblib

class NNObject:
    # 初始化模型和标准化器
    def __init__(self):
        self.loaded_model = tf.keras.models.load_model("timing/my_model.keras")
        self.scaler = joblib.load("timing/scaler.joblib")
        # 其他初始化代码...

    def get_hourly_trend(self):
        # 获取预测结果
        n_steps = 7
        df_plot = pd.read_csv('./timing/scenic_data.csv')
        x_values = df_plot.iloc[-n_steps:].values  # 取后七天数据
        x_latest = x_values.reshape(1, n_steps, x_values.shape[1])
        x_latest[0][-1][x_values.columns.get_loc('count')] = 0
        
        # 预测与反归一化
        predicted = self.loaded_model.predict(x_latest)
        predicted_counts = self.scaler.inverse_transform(predicted)  # 反归一化
        predicted_counts = predicted_counts > 0  # 转换为布尔值
        hourly_trend = predicted_counts[0].astype(int).tolist()
        print(hourly_trend)

if __name__ == '__main__':
    m = NNObject()
    m.get_hourly_trend()
